/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86187
 * Date: 2022-05-24
 * Time: 21:41
 */

class Node {
    int val;
    Node next = null;

    Node(int val) {
        this.val = val;
    }
}

public class ListNode {

    public Node head = null;

    //尾插法
    public void addLast(int data) {
        Node newNode = new Node(data);

        if(this.head == null) {
            this.head = newNode;
        } else {
            Node pos = this.head;
            while(pos.next != null) {
                pos = pos.next;
            }
            pos.next = newNode;
        }
    }

    //打印方法
    public void display(Node pHead) {
        Node pos = pHead;
        while(pos != null) {
            System.out.print(pos.val+" ");
            pos = pos.next;
        }
        System.out.println();
    }

    //销毁链表
    public void clear() {
        head = null;
    }

}
